package com.wn.budget.repository;

import com.wn.budget.model.Project;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

public interface ProjectRepository extends JpaRepository<Project, String> {
    Page<Project> findProjectByAdminId(String userId, Pageable pageable);

    @Query(value = "select p from Project p where " +
            "p.adminId =?4 and (?2 is null or p.createDate>=?2)    " +
            "and ( ?3 is null or p.createDate<=?3) and p.customerName like %?1%")
    Page<Project> findProjects(String name, Date beginDate, Date endDate, String userId, Pageable pageable);
}
